<template>
  <div>
    <el-card>
      <h3>模版下载</h3>
    </el-card>
    <el-card>
      <div>
        <el-form :inline="true" :model="DownUpline">
          <el-form-item label="上传用户:">
            <el-input v-model="DownUpline.DownUser" placeholder="用户ID/账号" clearable></el-input>
          </el-form-item>
          <el-form-item label="文件名:">
            <el-input v-model="DownUpline.DownName" placeholder="用户ID/账号" clearable></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary">查询</el-button>
          </el-form-item>
          <el-form-item>
            <el-button @click="Resetting">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
      <el-table :data="TemplateDown.records" style="width: 100%">
        <el-table-column prop="id" label="模型id">
        </el-table-column>
        <el-table-column prop="modelKey" label="模型标识key">
        </el-table-column>
        <el-table-column prop="modelName" label="模型名称(备注)">
        </el-table-column>
        <el-table-column prop="price" label="模型价格">
        </el-table-column>

        <el-table-column prop="modelFileName" label="文件名称">
        </el-table-column>
        <el-table-column prop="modelFileUrl" label="文件路径">
        </el-table-column>
        <el-table-column prop="enable" label="是否启用">
          <template slot-scope="scope">
            <el-switch v-model="scope.row.enable" disabled>
            </el-switch>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button type="text" icon="el-icon-delete" plain @click="downLoadFile(scope.row)" size="mini">下载</el-button>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :page-sizes="[10, 50, 100, 1000]" :page-size="10" layout="total, sizes, prev, pager, next, jumper"
        :total="TemplateDown.total" style="margin: 20px 0;float: right;">
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
import { ModelList,ModelDown} from '@/api/table'
import request from '../../../vue.config'
export default {
  data() {
    return {
      TemplateDown: [{
        date: '2016-05-02',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }, {
        date: '2016-05-04',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1517 弄'
      }, {
        date: '2016-05-01',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1519 弄'
      }, {
        date: '2016-05-03',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1516 弄'
      }],
      DownUpline: {
        DownUser: '',
        DownName: ''
      },
      pageCode: 1,
      pageSize: 10,
      RequestUrl:'',
    };
  },
  created() {
    this.getMObanLost()
    this.RequestUrl = request.devServer.proxy["/api"].target
  },
  methods: {



    async getMObanLost() {
      ModelList(this.pageCode, this.pageSize).then(res => {
        if (res.code === 1000) {
          this.TemplateDown = res.data.value
        } else {
          this.$message({
            message: res.message,
            type: 'error',
            duration: 1000
          });
        }
      })
    },

    // 下载
   async downLoadFile(row){
    const DownUrl = this.RequestUrl + `/datac/model/download?modelKey=${row.modelKey}`
    // console.log(DownUrl,"下载地址")
    window.open(DownUrl, '_blank')
    },

    async handleSizeChange(val) {
      this.pageSize = val;
      this.getMObanLost()
    },
    async handleCurrentChange(val) {
      this.pageCode = val;
      this.getMObanLost()

    },


    // 清空每一项的值
    clearObject(obj) {
      for (let key in obj) {
        if (obj.hasOwnProperty(key)) {
          obj[key] = '';
        }
      }
    },




    // 重置
    Resetting(){
      this.clearObject(this.DownUpline)
    }
  },
};
</script>

<style lang="scss" scoped></style>


